package com.jhgsys.internal.hazard.service.impl;

import com.jhgsys.internal.hazard.entity.HazardCautionaryDept;
import com.jhgsys.internal.hazard.mapper.HazardCautionaryDeptMapper;
import com.jhgsys.internal.hazard.service.IHazardCautionaryDeptService;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 警示教训部门 Service实现
 *
 * @author wanghw
 * @date 2024-08-20 09:23:14
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class HazardCautionaryDeptServiceImpl extends ServiceImpl<HazardCautionaryDeptMapper, HazardCautionaryDept> implements IHazardCautionaryDeptService {

    /**
     * 查询（分页）
     * @author wanghw
     * @date 2024-08-20 09:23:14
     * @param request QueryRequest
     * @param hazardCautionaryDept hazardCautionaryDept
     * @return IPage<HazardCautionaryDept>
    */
    @Override
    public IPage<HazardCautionaryDept> findHazardCautionaryDeptPage(QueryRequest request, HazardCautionaryDept hazardCautionaryDept) {
        LambdaQueryWrapper<HazardCautionaryDept> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardCautionaryDept::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<HazardCautionaryDept> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author wanghw
     * @date 2024-08-20 09:23:14
     * @param hazardCautionaryDept hazardCautionaryDept
     * @return List<HazardCautionaryDept>
     */
    @Override
    public List<HazardCautionaryDept> findHazardCautionaryDeptList(HazardCautionaryDept hazardCautionaryDept) {
	    LambdaQueryWrapper<HazardCautionaryDept> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HazardCautionaryDept::getDeletedFlg, 0);
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author wanghw
    * @date 2024-08-20 09:23:14
    * @param id
    * @return HazardCautionaryDept
    */
    @Override
    public HazardCautionaryDept findHazardCautionaryDeptById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author wanghw
     * @date 2024-08-20 09:23:14
     * @param hazardCautionaryDept hazardCautionaryDept
     */
    @Override
    @Transactional
    public void createHazardCautionaryDept(HazardCautionaryDept hazardCautionaryDept) {
        hazardCautionaryDept.setCreatedTime(new Date());
        this.save(hazardCautionaryDept);
    }

    /**
     * 修改
     * @author wanghw
     * @date 2024-08-20 09:23:14
     * @param hazardCautionaryDept hazardCautionaryDept
     */
    @Override
    @Transactional
    public void updateHazardCautionaryDept(HazardCautionaryDept hazardCautionaryDept) {
        hazardCautionaryDept.setUpdatedTime(new Date());
        this.saveOrUpdate(hazardCautionaryDept);
    }

    /**
     * 逻辑删除
     * @author wanghw
     * @date 2024-08-20 09:23:14
     * @param hazardCautionaryDept hazardCautionaryDept
     * @param hazardCautionaryDeptIds hazardCautionaryDeptIds
     */
    @Override
    @Transactional
    public void deleteHazardCautionaryDept(HazardCautionaryDept hazardCautionaryDept,String hazardCautionaryDeptIds) {
        List<String> list = Arrays.asList(hazardCautionaryDeptIds.split(StringPool.COMMA));
        this.baseMapper.update(hazardCautionaryDept,new LambdaQueryWrapper<HazardCautionaryDept>().in(HazardCautionaryDept::getCautionaryDeptId,list));
	}

    /**
    * 物理删除
    * @author wanghw
    * @date 2024-08-20 09:23:14
    * @param hazardCautionaryDeptIds hazardCautionaryDeptIds
    */
    @Override
    @Transactional
    public void physicallyDeleteHazardCautionaryDept(String hazardCautionaryDeptIds) {
        List<String> list = Arrays.asList(hazardCautionaryDeptIds.split(StringPool.COMMA));
        LambdaQueryWrapper<HazardCautionaryDept> wapper = new LambdaQueryWrapper<>();
        wapper.in(HazardCautionaryDept::getCautionaryDeptId,list);
        this.remove(wapper);
    }
}
